﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TournamentDatabase.Database;

namespace TournamentDatabase.Objects
{
	public class Competition
	{
		private int m_tid;
		private string m_type;
		private DateTime m_minBirthDate;
		private DateTime m_maxBirthDate;
		private Gender m_gender;
		private DateTime m_startDateTime;

		public int TournamentID
		{
			get { return m_tid; }
			set { m_tid = value; }
		}
		public string Type
		{
			get { return m_type; }
			set { m_type = value; }
		}
		public DateTime MinBirthDate
		{
			get { return m_minBirthDate; }
			set { m_minBirthDate = value; }
		}
		public DateTime MaxBirthDate
		{
			get { return m_maxBirthDate; }
			set { m_maxBirthDate = value; }
		}
		public Gender Gender
		{
			get { return m_gender; }
			set { m_gender = value; }
		}
		public DateTime StartDateTime
		{
			get { return m_startDateTime; }
			set { m_startDateTime = value; }
		}

		public Competition() : this(0, "", DateTime.Today, DateTime.Today, Gender.Male, DateTime.Now) { }
		public Competition(int tid, string type, DateTime minBirthDate, DateTime maxBirthDate, Gender gender, DateTime startDateTime)
		{
			m_tid = tid;
			m_type = type;
			m_minBirthDate = minBirthDate;
			m_maxBirthDate = maxBirthDate;
			m_gender = gender;
			m_startDateTime = startDateTime;
		}
		public Competition(OracleDataReader odr)
		{
			Gender = (Gender)Enum.Parse(typeof(Gender), odr["gender"].ToString(), true);
			TournamentID = int.Parse(odr["tid"]);
			MinBirthDate = DateTime.Parse(odr["minBirthDate"]);
			MaxBirthDate = DateTime.Parse(odr["maxBirthDate"]);
			Type = odr["type"].ToString();
			StartDateTime = DateTime.Parse(odr["startDateTime"]);
		}

		public static List<Competition> ParseCompetition(OracleDataReader odr)
		{
			List<Competition> list = new List<Competition>();
			while (odr.Read())
			{
				list.Add(new Competition(odr));
			}
			return list;
		}
	}
}
